import type { CallResult, IndexDataBean, LoginRespBean } from '@/components/baseBean'
import { isEmpty, MyService } from '@/utils/httputils'
import CryptoJS from 'crypto-js'
export default class MyApi {
  /**
   * 登录
   */
  static async login(phone: string, passWord: string): Promise<CallResult<LoginRespBean>> {
    //模拟构造一个返回值
    if (isEmpty(phone) || isEmpty(passWord)) {
      return {
        code: 400,
        message: '请输入用户名和密码',
      }
    }
    const data: LoginRespBean = {
      token: '1231313',
      userName: '张三',
      roleId: 1,
      roleName: '管理员',
    }
    const result: CallResult<LoginRespBean> = {
      code: 200,
      message: '',
      data: data,
    }
    return result
  }
  static login1(phone: string, passWord: string) {
    const params = {
      phone: phone,
      passWord: CryptoJS.MD5(passWord).toString(),
    }
    return MyService.apiPost<LoginRespBean>('/api/sysuser/login', params)
  }
  /*---------------------------------------------------------*/
  /**
   * 首页.IndexDataBean
   */
  static getIndex() {
    return MyService.apiGet<IndexDataBean>('/api/com/getIndex')
  }
}
